//
//  HWChangchyongViewController.m
//  HWPromoteProjectAPP
//
//  Created by 陈道斌 on 2020/3/9.
//  Copyright © 2020 陈道斌. All rights reserved.
//

#import "HWChangchyongViewController.h"
#import "HWWebViewGameViewController.h"
#import "HWChongzhijiemianViewController.h"
#import "HWChongzhishibaiViewController.h" // 充值失败

@interface HWChangchyongViewController ()
@property (weak, nonatomic) IBOutlet UIView *kapianView;
@property (weak, nonatomic) IBOutlet UILabel *jingELabel;
@property (weak, nonatomic) IBOutlet UIView *zhanghuzongeLabel;
@property (weak, nonatomic) IBOutlet UITextField *shurutextField;
@property (weak, nonatomic) IBOutlet UIButton *tijianbut;
@property (strong,nonatomic) NSString *oidStr;
@property (strong,nonatomic) NSString *chongzhijinger; // 充值金额




@end

@implementation HWChangchyongViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupshuxing];

    [self setupUI];
    
    

}


- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    if (self.oidStr != nil) {
        
        [self chaxundingdang];
        
    }
    
}



//  查询订单
- (void)chaxundingdang {
    
    
    
    
    

    NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
    NSString *uid =  [HWLocallyStoredData getLoginUserID];
    NSString *signStr = [NSString stringWithFormat:@"%@%@%@%@",uid,self.oidStr,tStr,@"adesxloksy13s98adv"];
    NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];

    NSDictionary *parametes = @{        @"ios" : @"1",
                                   @"ct" : @"app",
                                   @"ac" : @"recharge_log",
                                   @"t" : tStr,
                                   @"oid" : self.oidStr,
                                   @"uid":uid,
                                   @"sign" :signStrMd5
                                   };


       [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {



             NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
             if ([codeStr intValue] == 1) {

                      NSLog(@"%@",response);


                    HWChongzhijiemianViewController  *chong = [[HWChongzhijiemianViewController alloc]init];
                    chong.oidStr = self.oidStr;
                    chong.chongzhijinger = self.chongzhijinger;
                    CGFloat  chongzhi = [self.chongzhijinger floatValue];
                    CGFloat  zongjing = [self.cunchuStr floatValue];
                    CGFloat  zonge = chongzhi + zongjing;
                    chong.zongjinge = [NSString stringWithFormat:@"%.2f",zonge];
                  //  [self.navigationController pushViewController:chong animated:YES];
                 
                    [self addChildViewController:chong];
                   chong.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
                     [self.view addSubview:chong.view];
                 
        
                    

             } else {

                //  [MBProgressHUD showError:response[@"message"]];

//                 HWChongzhijiemianViewController  *chong = [[HWChongzhijiemianViewController alloc]init];
//                 chong.oidStr = self.oidStr;
//                 chong.chongzhijinger = self.chongzhijinger;
//                 CGFloat  chongzhi = [self.chongzhijinger floatValue];
//                 CGFloat  zongjing = [self.cunchuStr floatValue];
//                 CGFloat  zonge = chongzhi + zongjing;
//                 chong.zongjinge = [NSString stringWithFormat:@"%.2f",zonge];
//                // [self.navigationController pushViewController:chong animated:YES];
//
//                 [self addChildViewController:chong];
//                 chong.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
//                 [self.view addSubview:chong.view];
                 
                    HWChongzhishibaiViewController *shiba = [[HWChongzhishibaiViewController alloc]init];
                   [self addChildViewController:shiba];
                   shiba.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
                   [self.view addSubview:shiba.view];
                 
                 


             }



         } failure:^(NSString *error) {
            // [SVProgressHUD dismiss];

             [MBProgressHUD showSuccess:@"登录失败"];
             [MBProgressHUD hideHUD];




         }];

    
    
    
    
    
//    HWChongzhijiemianViewController  *chong = [[HWChongzhijiemianViewController alloc]init];
//    chong.oidStr = self.oidStr;
//    chong.chongzhijinger = self.chongzhijinger;
//    [self.navigationController pushViewController:chong animated:YES];
    
    
    
    
    
    
    
    
    
    
}

// 设置常用的属性
- (void)setupshuxing {
    
    self.view.backgroundColor = beijingyanSe;
    self.navigationItem.title = @"充值";
    
    self.kapianView.layer.cornerRadius = 12;
    self.kapianView.layer.masksToBounds = YES;
    
    
     self.jingELabel.text = [NSString stringWithFormat:@"%@",self.cunchuStr];
    
    
    
    
    
    
    
}

// 设置UI
-(void)setupUI {
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapview)];
    [self.view addGestureRecognizer:tap];
    self.kapianView.backgroundColor = [UIColor whiteColor];
    
    [self.tijianbut addTarget:self action:@selector(tijiaoTap) forControlEvents:UIControlEventTouchUpInside];
    
    
    
      
    
    
}


- (void)tapview {
    
    [self.view endEditing:YES];
    
}

- (void)tijiaoTap {
   
    NSLog(@"uhiochio'hio'hio");
    [self sendNetworkRequest];
    
    
    
    
}


- (void)sendNetworkRequest {
    
       [self.shurutextField resignFirstResponder];
    
      if (!(self.shurutextField.text.length > 0)) {
          [MBProgressHUD showError:@"请输入金额"];
          return;
      }
           
         self.chongzhijinger = self.shurutextField.text;
    
         NSString *money = [NSString stringWithFormat:@"%@",self.shurutextField.text];
         NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
         NSString *uid =  [HWLocallyStoredData getLoginUserID];
         NSString *signStr = [NSString stringWithFormat:@"%@%@%@%@",uid,money,tStr,@"adesxloksy13s98adv"];
         NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];
      
        
        
        
          NSDictionary *parametes = @{      @"ios" : @"1",
                                       @"ct" : @"app",
                                        @"ac" : @"recharge",
                                        @"t" : tStr,
                                        @"uid":uid,
                                        @"money":money,
                                        @"sign" :signStrMd5
                                            
                                        };
        
        
            [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
                  
                 

                  NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                  if ([codeStr intValue] == 1) {
                 
                        NSLog(@"%@",response);
                      
//                      self.dataDic = response[@"data"];
//                      self.zeongjingerLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"money"]];
//                      self.fengxiangyongjingLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"shareMoney"]];
//                      self.yitixianjingLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"withdraw"]];
 //                     [self.mainTabelView reloadData];
                      self.oidStr =  [NSString stringWithFormat:@"%@",response[@"data"][@"oid"]];
                      
            
                      
                   HWWebViewGameViewController *webview = [[HWWebViewGameViewController alloc]init];
                   webview.urlString = [NSString stringWithFormat:@"%@",response[@"data"][@"url"]];
                   webview.gname = @"充值";
                   webview.hidesBottomBarWhenPushed = YES;
                   [self.navigationController pushViewController:webview animated:YES];
                      
                      
                      
                 
                      
                
                

                       
                  } else {
                      
                    [MBProgressHUD showError:response[@"message"]];
                                    
                
                      
                  }
                  
             
                  
              } failure:^(NSString *error) {
                 // [SVProgressHUD dismiss];
                  
                  [MBProgressHUD showSuccess:@"登录失败"];
                  [MBProgressHUD hideHUD];
                  
                  
                  
                  
              }];
        
    
}




@end
